home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_321 / ifs / source / gadmsg.c next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  164 lines

  1. /* a GADGETUP has been received, this routine 
  2.    takes the appropriate action
  3. */
  4.  
  5. #include "ifs.h"
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>
  8.  
  9. int checkvalidfun (funstr, currentfun, numoffun)
  10.   char *funstr;
  11.   int  currentfun, numoffun;
  12. {
  13.   int  numscaned,
  14.   fnum = 0;
  15.  
  16.   numscaned = sscanf(funstr, "%5d", &fnum);
  17.   if ((numscaned>2) || (numscaned==0) || (fnum>FUNLIMIT) || (fnum<1))
  18.     return(currentfun);
  19.   else
  20.   return(fnum-1);        /* current function is 1 less than displayed */
  21. }         
  22.  
  23. float checkvalidcooef (funstr, cooef)
  24.    char *funstr;
  25.    float cooef;
  26.    
  27. {
  28.    int  numscaned;
  29.    float   scooef = 0.;
  30.  
  31.    numscaned = sscanf(funstr,"%5f", &scooef);
  32.    if ((numscaned == 0) || (scooef > MAXCOFF) || (scooef < MINCOFF))
  33.       return(cooef);
  34.    else
  35.       return(scooef);
  36. }         
  37.  
  38. float checkvalidper (funstr, per)
  39.    char *funstr;
  40.    float per;
  41.    
  42. {
  43.    int  numscaned;
  44.    float   sper = 0.;
  45.  
  46.    numscaned = sscanf(funstr, "%5f", &sper);
  47.    if ((numscaned == 0) || (sper > 1.) || (sper < 0.))
  48.       return(per);
  49.    else
  50.       return(sper);
  51. }         
  52.       
  53.     
  54. void setpots(adjwin, gads, PInfos, funs, percent, 
  55.              xyscale, xoff, yoff, currentfun, numoffun, stxt, adjopen) 
  56.  
  57.   struct Window *adjwin;
  58.   struct Gadget *gads;
  59.   struct PropInfo *PInfos;
  60.   float funs[][6], percent[], xyscale;
  61.   int    xoff, yoff, currentfun, numoffun;
  62.   UBYTE stxt[NUMSTRS][GSTRLEN];
  63.   short adjopen;
  64. {
  65.   int i;
  66.   if (adjopen) {
  67.     if(numoffun>0) 
  68.       PInfos[0].HorizPot = currentfun*FFFF / numoffun;  
  69.     for(i=0; i<6; i++) 
  70.       PInfos[i+1].HorizPot = (funs[currentfun][i]+1)*FFFF/3;
  71.     PInfos[7].HorizPot = (currentfun>0) 
  72.                      ? (percent[currentfun]-percent[currentfun-1])*FFFF
  73.                      : percent[currentfun]*FFFF;
  74.     PInfos[8].VertPot  = xyscale*FFFF/3;
  75.     PInfos[9].HorizPot= ((xoff/(float)WIDTH)+1)*FFFF/3;
  76.     PInfos[9].VertPot = FFFF *(.66 - (yoff/(3. * HEIGHT)));
  77.     sprintf(stxt[0],"%5d",currentfun+1);
  78.     for(i=0; i<6; i++)            /* change needed */
  79.       sprintf(stxt[i+1],"%5.2f", funs[currentfun][i]);
  80.     sprintf(stxt[7],"%5.2f", (currentfun>0) 
  81.                              ? percent[currentfun]-percent[currentfun-1] 
  82.                              : percent[currentfun]);
  83.     PInfos[0].HorizBody = FFFF / (numoffun+1);
  84.     if((adjwin->DetailPen = (currentfun+2)%MAXCOLORS) < 2)
  85.       adjwin->DetailPen = adjwin->DetailPen + 2;
  86.     RefreshGadgets(&gads[NUMGADS-1],adjwin,NULL);
  87.   }
  88. }
  89.  
  90. void adjpercent(numoffun, percent)
  91. int numoffun;
  92. float percent[];
  93. {
  94.   int i;
  95.  
  96.   percent[0] = 1.0/(numoffun+1);
  97.   for (i=1;i<=numoffun;i++) {
  98.     percent[i] = percent[i-1] + 1.0/(numoffun+1);
  99.        
  100.   }
  101. }
  102.  
  103. void gadgetmessage(aptr,adjwin,funs,percent,xyscale,xoff,yoff,gads,PInfos,
  104.                    numoffun,currentfun,stxt,displaynumsw,adjopen)
  105. /* returns whether or not the screen needs to be cleared */
  106. APTR aptr;
  107. float funs[][6],percent[],*xyscale;
  108. int   *xoff, *yoff,  *numoffun, *currentfun;
  109. struct Gadget *gads;
  110. struct Window *adjwin;
  111. struct PropInfo *PInfos;
  112. UBYTE stxt[NUMSTRS][GSTRLEN];
  113. short displaynumsw;
  114. {
  115.  
  116.   short needrefresh = TRUE;
  117.   int i;
  118.  
  119.   if (aptr == (APTR)&gads[0]) { 
  120.       /* this *numoffun+1 insures that Pot is placed right */
  121.       *currentfun = PInfos[0].HorizPot * (*numoffun+1)/ FFFF;
  122.       /* insure that currentfun is always <= numoffun */
  123.       if (*currentfun > *numoffun) (*currentfun)--; 
  124.       needrefresh = FALSE;
  125.   }
  126.   else if (aptr == (APTR)&gads[7]) {
  127.       percent[*currentfun] = (PInfos[7].HorizPot*1/ (float) FFFF); /*comp bug*/
  128.       if (*currentfun>0) percent[*currentfun] += percent[*currentfun-1];
  129.       }
  130.   else if (aptr == (APTR)&gads[8])              
  131.       *xyscale = (PInfos[8].VertPot*3/(float) FFFF);
  132.   else if (aptr == (APTR)&gads[9]) {
  133.       *xoff = ((PInfos[9].HorizPot*3/(float) FFFF) - 1)*WIDTH;
  134.       *yoff = HEIGHT * (2.0 - (3. * (PInfos[9].VertPot*1) / (float) FFFF)); 
  135.       /* another compiler bug*/
  136.   }
  137.   else if (aptr == (APTR)&gads[10]) {    /* Function Number String */
  138.       *currentfun = checkvalidfun(stxt[0],*currentfun,*numoffun);
  139.       if(*numoffun < *currentfun) {
  140.         *numoffun = *currentfun;
  141.         adjpercent(*numoffun, percent);
  142.         PInfos[0].HorizBody = FFFF / (*numoffun+1);
  143.         needrefresh = displaynumsw;
  144.       }
  145.       else needrefresh = FALSE;
  146.   }
  147.   else if (aptr == (APTR)&gads[17]) {
  148.       percent[*currentfun] = checkvalidper(stxt[7], percent[*currentfun]);
  149.       if (*currentfun>0) percent[*currentfun] += percent[*currentfun-1];
  150.       }
  151.  
  152.   for (i=0; i<6; i++) {         /* change needed */
  153.     if (aptr == (APTR)&gads[i+1]) 
  154.       funs[*currentfun][i] = ((PInfos[i+1].HorizPot)*3/(float) FFFF) - 1.0;
  155.     if (aptr == (APTR)&gads[i+11])   /* one of the other strings */
  156.       funs[*currentfun][i] = checkvalidcooef(stxt[i+1], funs[*currentfun][i]);
  157.   }
  158.  
  159.   setpots(adjwin, gads, PInfos, funs, percent, *xyscale, 
  160.           *xoff, *yoff, *currentfun, *numoffun, stxt, adjwin);
  161.   if (needrefresh) clearscreen();
  162. }
  163.  
  164.